package com.bluetoothsms.common;

public class Common {
	public final static String UUID = "6ebd20b0-e12a-11e1-9b23-0800200c9a66";
	public final static int MSG_CONNECTED = 1;
	public final static int MSG_CONNECTION_CLOSED = 2;
	public final static int MSG_CONNECTION_FAILED = 3;
	public final static long ALIVE_INTERVAL = 5000;

	public final static String DELIMITER = "\n";

	public enum ConnectionState {
		Disconnected, Connecting, Connected
	}

	public enum CallLogType {
		Incoming, Outgoing, Missed
	}
	
	public enum SmsStatus {
		Received, Delivered, Sent, Sending, Unknown;

		static SmsStatus fromAndroidStatus(int androidStatus) {
			switch (androidStatus) {
			case -1:
				return Received;

			case 0:
				return Delivered;

			case 34:
				return Sent;

			default:
				return Unknown;
			}
		}

		public int toAndroidStatus() {
			switch (this) {
			case Received:
				return -1;

			case Sent:
				return 34;

			case Delivered:
				return 0;

			default:
				return -1;
			}
		}

		@Override
		public String toString() {
			switch (this) {
			case Received:
				return "Empfangen";
			case Sent:
				return "Nicht zugestellt";
			case Delivered:
				return "Zugestellt";
			case Sending:
				return "Wird gesendet";
			default:
				return "Unbekannt";
			}
		}
	}

	public enum SmsType {
		Received, Sent, Draft, Unknown;

		static SmsType fromAndroidType(int androidType) {
			switch (androidType) {
			case 1:
				return Received;

			case 2:
				return Sent;

			case 3:
				return Draft;

			default:
				return Unknown;
			}
		}

		public int toAndroidType() {
			switch (this) {
			case Received:
				return 1;

			case Sent:
				return 2;

			case Draft:
				return 3;

			default:
				return -1;
			}
		}

		@Override
		public String toString() {
			switch (this) {
			case Received:
				return "Empfangen";
			case Sent:
				return "Gesendet";
			case Draft:
				return "Entwurf";
			default:
				return "Unbekannt";
			}
		}

	}

	private Common() {

	}

	public static String join(String[] arr) {
		StringBuilder b = new StringBuilder();

		if (arr != null && arr.length > 0) {
			for (String s : arr) {
				b.append(s);
				b.append(DELIMITER);
			}

			// Letzten Delimiter entfernen
			b.deleteCharAt(b.length() - 1);
		}

		return b.toString();
	}
}
